import { BaseEntity, EntityTarget } from "typeorm"
import { AccountEntity } from "../../account_server/entity/AccountEntity"
import { UserEntity } from "../../account_server/entity/UserEntity"
import { UserResourceEntity } from "../../account_server/entity/UserResourceEntity"
import { ClubEntity } from "../../hall_server/entity/ClubEntity"
import { ClubUserEntity } from "../../hall_server/entity/ClubUserEntity"
import { RoomEntity } from "../../hall_server/entity/RoomEntity"
import { RoomTemplateEntity } from "../../hall_server/entity/RoomTemplateEntity"
import { UserRoomEntity } from "../../hall_server/entity/UserRoomEntity"
import { Logger } from "../engine/utils/Logger"

export class DbConfig {

    public static Db_Type = {
        Dev: 1,
        Test: 2,
        Online: 3,
    }

    public static now_db_type: number = DbConfig.Db_Type.Test

    public static Db_Name = {
        db_account: "db_legend_account", //账号数据库
        db_game: "db_legend_game", //游戏数据库
        db_admin: "db_legend_admin", //后台数据库
        db_log: "db_legend_log", //日志数据库
    }

    public host: string = ""
    public port: number = 3306
    public user: string = ""
    public pass: string = ""

    constructor(host: string, port: number, user: string, pass: string) {
        this.host = host;
        this.port = port;
        this.user = user;
        this.pass = pass;
    }

    private static dbMap: Map<number, DbConfig> = new Map<number, DbConfig>()
        .set(DbConfig.Db_Type.Dev, new DbConfig("121.37.251.120", 3306, "root", "f301517757c8cf6c"))
        .set(DbConfig.Db_Type.Test, new DbConfig("127.0.0.1", 3306, "root", "f301517757c8cf6c"))
        .set(DbConfig.Db_Type.Online, new DbConfig("127.0.0.1", 3306, "root", "f301517757c8cf6c"))

    public static init(dbType: number = DbConfig.Db_Type.Dev) {
        this.now_db_type = dbType

    }

    public static getDbConfig(dbType: number): DbConfig {
        let db: DbConfig = this.dbMap.get(dbType);
        if (db) {
            return db;
        } else {
            Logger.error("不存在数据库配置:" + dbType)
        }
    }

    private static dbEntityMap: Map<string, Array<any>> = new Map<string, Array<any>>()
        .set(DbConfig.Db_Name.db_account, [AccountEntity])
        .set(DbConfig.Db_Name.db_game, [
         
        ])
        .set(DbConfig.Db_Name.db_admin, [])
        .set(DbConfig.Db_Name.db_log, [])

    public static getDbEntity(dbName: string): Array<any> {
        return this.dbEntityMap.get(dbName)
    }
}